package com.ujs.edu.demo.dao;

import com.ujs.edu.demo.dataobject.BcBooks;
import java.util.List;

import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;
import org.springframework.web.bind.annotation.PathVariable;

@Mapper
public interface BcBooksMapper {
    @Delete({
        "delete from bc_books",
        "where book_id = #{bookId,jdbcType=INTEGER}"
    })
    int deleteByPrimaryKey(Integer bookId);

    @Insert({
        "insert into bc_books (book_id, book_name, ",
        "book_num, brief, ",
        "description, makt_able, ",
        "cart_id, createtime, ",
        "modifytime, author, ",
        "cover, memberId)",
        "values (#{bookId,jdbcType=INTEGER}, #{bookName,jdbcType=VARCHAR}, ",
        "#{bookNum,jdbcType=INTEGER}, #{brief,jdbcType=VARCHAR}, ",
        "#{description,jdbcType=VARCHAR}, #{maktAble,jdbcType=INTEGER}, ",
        "#{cartId,jdbcType=VARCHAR}, now(), ",
        "now(), #{author,jdbcType=VARCHAR}, ",
        "#{cover,jdbcType=VARCHAR}, #{memberid,jdbcType=INTEGER})"
    })
    int insert(BcBooks record);

    @Select({
        "select",
        "book_id, book_name, book_num, brief, description, makt_able, cart_id, createtime, ",
        "modifytime, author, cover, memberId",
        "from bc_books",
        "where book_id = #{bookId,jdbcType=INTEGER}"
    })
    @Results({
        @Result(column="book_id", property="bookId", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="book_name", property="bookName", jdbcType=JdbcType.VARCHAR),
        @Result(column="book_num", property="bookNum", jdbcType=JdbcType.INTEGER),
        @Result(column="brief", property="brief", jdbcType=JdbcType.VARCHAR),
        @Result(column="description", property="description", jdbcType=JdbcType.VARCHAR),
        @Result(column="makt_able", property="maktAble", jdbcType=JdbcType.INTEGER),
        @Result(column="cart_id", property="cartId", jdbcType=JdbcType.VARCHAR),
        @Result(column="createtime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="modifytime", property="modifytime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="author", property="author", jdbcType=JdbcType.VARCHAR),
        @Result(column="cover", property="cover", jdbcType=JdbcType.VARCHAR),
        @Result(column="memberId", property="memberid", jdbcType=JdbcType.INTEGER)
    })
    BcBooks selectByPrimaryKey(Integer bookId);

    @Select({
        "select",
        "book_id, book_name, book_num, brief, description, makt_able, cart_id, createtime, ",
        "modifytime, author, cover, memberId",
        "from bc_books"
    })
    @Results(id = "bookMap",value = {
        @Result(column="book_id", property="bookId", jdbcType=JdbcType.INTEGER, id=true),
        @Result(column="book_name", property="bookName", jdbcType=JdbcType.VARCHAR),
        @Result(column="book_num", property="bookNum", jdbcType=JdbcType.INTEGER),
        @Result(column="brief", property="brief", jdbcType=JdbcType.VARCHAR),
        @Result(column="description", property="description", jdbcType=JdbcType.VARCHAR),
        @Result(column="makt_able", property="maktAble", jdbcType=JdbcType.INTEGER),
        @Result(column="cart_id", property="cartId", jdbcType=JdbcType.VARCHAR),
        @Result(column="createtime", property="createtime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="modifytime", property="modifytime", jdbcType=JdbcType.TIMESTAMP),
        @Result(column="author", property="author", jdbcType=JdbcType.VARCHAR),
        @Result(column="cover", property="cover", jdbcType=JdbcType.VARCHAR),
        @Result(column="memberId", property="memberid", jdbcType=JdbcType.INTEGER)
    })
    List<BcBooks> selectAll();

    //少选上架商品
    @Select({
            "select",
            "book_id, book_name, book_num, brief, description, makt_able, cart_id, createtime, ",
            "modifytime, author, cover, memberId",
            "from bc_books",
            "where makt_able=#{maktable}"
    })
    @ResultMap("bookMap")
    List<BcBooks> selectByMaktable(@Param("maktable")Integer maktable);

    //模糊搜索
    @Select({
            "select",
            "book_id, book_name, book_num, brief, description, makt_able, cart_id, createtime, ",
            "modifytime, author, cover, memberId",
            "from bc_books",
            "where book_name like concat('%',#{input},'%')"
    })
    @ResultMap("bookMap")
    List<BcBooks> selectLike(@Param("input") String input);

    //动态筛选
    @SelectProvider(type = BookBuildQuery.class,method = "queryBuiler")
    @ResultMap("bookMap")
    List<BcBooks> dynamicFind(@Param("bcBooks")BcBooks bcBooks);

    //根据分类查询
    @Select({
            "select",
            "book_id, book_name, book_num, brief, description, makt_able, cart_id, createtime, ",
            "modifytime, author, cover, memberId",
            "from bc_books",
            "where cart_id=#{cartId}"
    })
    @ResultMap("bookMap")
    List<BcBooks> selectByCartId(@Param("cartId") String cartId);


    //自动推荐
    @Select({
            "select",
            "book_id, book_name, book_num, brief, description, makt_able, cart_id, createtime, ",
            "modifytime, author, cover, memberId",
            "from bc_books"
    })
    @ResultMap("bookMap")
    List<BcBooks> selectByScore();


    @Update({
        "update bc_books",
        "set book_name = #{bookName,jdbcType=VARCHAR},",
          "book_num = #{bookNum,jdbcType=INTEGER},",
          "brief = #{brief,jdbcType=VARCHAR},",
          "description = #{description,jdbcType=VARCHAR},",
          "makt_able = #{maktAble,jdbcType=INTEGER},",
          "cart_id = #{cartId,jdbcType=VARCHAR},",
          "modifytime = now(),",
          "author = #{author,jdbcType=VARCHAR},",
          "cover = #{cover,jdbcType=VARCHAR},",
          "memberId = #{memberid,jdbcType=INTEGER}",
        "where book_id = #{bookId,jdbcType=INTEGER}"
    })
    int updateByPrimaryKey(BcBooks record);

    //下架
    @Update({
            "update bc_books",
            "set makt_able=0",
            "where book_id=#{bookId}"
    })
    int updateunmaktable(@Param("bookId") Integer bookId);

    //下架
    @Update({
            "update bc_books",
            "set makt_able=1",
            "where book_id=#{bookId}"
    })
    int updatemaktable(@Param("bookId") Integer bookId);
    //修改上架书籍信息
    @Update({
            "update bc_books",
            "set book_name=#{bookName},",
            "book_num=#{bookNum},",
            "author=#{author},",
            "brief=#{brief}",
            "where book_id=#{bookId}"
    })
    int updateInform(BcBooks bcBooks);
}